package com.hig.ledger.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hig.ledger.domain.LedgerWorkPermit;
import com.hig.ledger.service.ILedgerWorkPermitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 特种作业许可证清单Controller
 * 
 * @author scp
 * @date 2024-09-22
 */
@RestController
@RequestMapping("/ledger/permit")
public class LedgerWorkPermitController extends BaseController
{
    @Autowired
    private ILedgerWorkPermitService ledgerWorkPermitService;

    /**
     * 查询特种作业许可证清单列表
     */
    @PreAuthorize("@ss.hasPermi('ledger:permit:list')")
    @GetMapping("/list")
    public TableDataInfo list(LedgerWorkPermit ledgerWorkPermit)
    {
        startPage();
        List<LedgerWorkPermit> list = ledgerWorkPermitService.selectLedgerWorkPermitList(ledgerWorkPermit);
        return getDataTable(list);
    }

    /**
     * 导出特种作业许可证清单列表
     */
    @PreAuthorize("@ss.hasPermi('ledger:permit:export')")
    @Log(title = "特种作业许可证清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(LedgerWorkPermit ledgerWorkPermit, HttpServletResponse response)
    {
        List<LedgerWorkPermit> list = ledgerWorkPermitService.selectLedgerWorkPermitList(ledgerWorkPermit);
        ExcelUtil<LedgerWorkPermit> util = new ExcelUtil<LedgerWorkPermit>(LedgerWorkPermit.class);
        util.exportExcel(response, list, "特种作业许可证清单数据");
    }

    /**
     * 获取特种作业许可证清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('ledger:permit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ledgerWorkPermitService.selectLedgerWorkPermitById(id));
    }

    /**
     * 新增特种作业许可证清单
     */
    @PreAuthorize("@ss.hasPermi('ledger:permit:add')")
    @Log(title = "特种作业许可证清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LedgerWorkPermit ledgerWorkPermit)
    {
        return toAjax(ledgerWorkPermitService.insertLedgerWorkPermit(ledgerWorkPermit));
    }

    /**
     * 修改特种作业许可证清单
     */
    @PreAuthorize("@ss.hasPermi('ledger:permit:edit')")
    @Log(title = "特种作业许可证清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LedgerWorkPermit ledgerWorkPermit)
    {
        return toAjax(ledgerWorkPermitService.updateLedgerWorkPermit(ledgerWorkPermit));
    }

    /**
     * 删除特种作业许可证清单
     */
    @PreAuthorize("@ss.hasPermi('ledger:permit:remove')")
    @Log(title = "特种作业许可证清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ledgerWorkPermitService.deleteLedgerWorkPermitByIds(ids));
    }
}
